import axios from 'axios';
import router from '@/router';
import {
    MessageBox
} from "element-ui";

const service = axios.create({
    baseURL: 'http://172.16.88.5:8880/',
    timeout: 5000
});

service.interceptors.request.use(
    config => {
        let token = sessionStorage.getItem("Access-Token");
        if (token) {
            config.headers.Authorization = `Bearer ${token}`;
        }
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject(error);
    }
);

service.interceptors.response.use(
    response => {
        return response.data;
    },
    error => {
        /*if (error.response.status === 401) {
            //重新登录
            MessageBox.confirm(
                "您已经退出登录，请确认是否重新登录！",
                "重新登录确认", {
                    confirmButtonText: "重新登录",
                    cancelButtonText: "拒绝",
                    type: "warning"
                }).then(() => {
                    router.replace({
                        path: '/login',
                        query: { redirect: router.currentRoute.fullPath }
                      })
            });
        } else {
            return Promise.reject(error);
        }*/
    }
);

export default service;